// Copyright 2023 The titan Authors. All rights reserved.

// Project: titan
// IDE: GoLand
// Author: fucaihe@outlook.com
// File: wire.go
// Date: 2023/12/18 14:00:49
// Description: 依赖注入

//go:build wireinject
// +build wireinject

package main

import (
	"github.com/google/wire"
	"github.com/smallnest/rpcx/server"
	"github.com/spf13/viper"

	"titan/internal/api"
	"titan/internal/cache"
	"titan/internal/serve"
	"titan/internal/service"
	"titan/pkg/log"
)

// RPC 服务
var ServerSet = wire.NewSet(serve.NewServerRPC)

// Redis 缓存
var CacheSet = wire.NewSet(cache.NewRedis)

// 分布式锁
// var mutexLock = wire.NewSet(
//	mutex.NewClient,
//	mutex.NewRedsync,
//	mutex.NewDefaultMutex,
// )

// RPC 接口
var APISet = wire.NewSet(
	api.NewAPI,
	api.NewArithAPI,
	api.NewNewsIndex,
)

// 处理逻辑
var ServiceSet = wire.NewSet(
	service.NewService,
	service.NewNewsIndexService,
)

func newApp(*viper.Viper, *log.Logger) (*server.Server, func(), error) {
	panic(wire.Build(
		ServerSet,
		CacheSet,
		APISet,
		ServiceSet,
	))
}
